/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function disp_confirm(messageText,yesUrl,noUrl)
{
    var r=confirm(messageText)
    if (r==true)
    {
        window.location = yesUrl;
    }
    else
    {
        window.location = noUrl;
    }
}
function getXMLHttp()
{
    var xmlHttp

    try
    {
        //Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch(e)
    {
        //Internet Explorer
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e)
            {
                alert("Your browser does not support AJAX!")
                return false;
            }
        }
    }
    return xmlHttp;
}

function MakeRequest(url,area)
{
    var xmlHttp = getXMLHttp();
  
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 1)
        {
            var content="<div style=\"width:100%; text-align: center;\"><img src=\"img/loading.gif\"></div>";
            HandleResponse(content,area);
        }
        if(xmlHttp.readyState == 4)
        {
            HandleResponse(xmlHttp.responseText,area);
        }
    }

    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function getAjaxContent(url)
{
    var xmlHttp = getXMLHttp();
    var resultHTML;
  
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 1)
        {
        //var content="<img align=\"center\" src=\"img/loading.gif\">";
        //HandleResponse(content,area);
        }
        if(xmlHttp.readyState == 4)
        {
            resultHTML=xmlHttp.responseText;
        }
    }

    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
    return resultHTML;
}

function HandleResponse(response,responseDiv)
{
    document.getElementById(responseDiv).innerHTML = response;
}

function openWindow(strUrl, strWindowName, strWindowFeatures){
    
    window.open(strUrl, strWindowName, strWindowFeatures)
}

function loadIndex(){
    var height=window.innerHeight;
    var width=window.innerWidth;
    var mapWidth=width-360;
    
    $('mainContent').hide();
    $('status').innerHTML="<div style=\"width:100%;\">Yükleniyor...</div>";
    $('mapLayer').setOpacity(0.8); //Decrease opacity of Map Layer
    initializeMap();
    
    
    
    //Ajax Request for Search
    new Ajax.Request('parts/index/searchTab.php' ,
    {
        method:'get',
        onLoading: function(){
           $('searchBox').innerHTML=showLoadingImage();
        },
        onSuccess: function(transport){
            var response = transport.responseText || "no response text";
            $('searchBox').innerHTML=response;
        },
        onFailure: function(){
            alert('Something went wrong...');
        }
    });
    
     //Ajax Request for Map
    new Ajax.Request('parts/index/map.php' ,
    {
        method:'get',
        onLoading: function(){
           
        },
        onSuccess: function(transport){
            var response = transport.responseText || "no response text";
            $('mainContent').innerHTML=response;
        },
        onFailure: function(){
            alert('Something went wrong...');
        }
    });
    
    //Ajax Request for Results
    new Ajax.Request('parts/index/resultGrid.php' ,
    {
        method:'get',
        onLoading: function(){
           
        },
        onSuccess: function(transport){
            var response = transport.responseText || "no response text";
            $('result').innerHTML=response;
            $('status').innerHTML="<div style=\"width:100%;\">Yüklendi...</div>";
            $('status').fade({ duration: 3.0 });
        },
        onFailure: function(){
            alert('Something went wrong...');
        }
    });
}

function loadAddPropertyMap(){
    //$('status').appear();
    $('status').innerHTML="<div style=\"width:100%;\">Yükleniyor...</div>";
    initializeAddPropertyMap();
    
    //Ajax Request for Bubble
    new Ajax.Request('parts/addProperty/status.php' ,
    {
        method:'get',
        onLoading: function(){
           
        },
        onSuccess: function(transport){
            var response = transport.responseText || "no response text";
            $('addStatus').innerHTML=response;
            $('status').innerHTML="<div style=\"width:100%;\">Yüklendi...</div>";
            $('status').fade({ duration: 3.0 });
        },
        onFailure: function(){
            alert('Something went wrong...');
        }
    });
}

function addProperty(){
    var offerType=document.getElementById('offerType').value;
    var type=document.getElementById('propertyType').value;
    var city=document.getElementById('city').value;
    var price=document.getElementById('price').value;
    var area=document.getElementById('area').value;
    var lat=document.getElementById('lat').value;
    var lng=document.getElementById('lng').value;
    var details=document.getElementById('details').value;
    
    var url="process/propertyAdd.php?offerType="+offerType+"&type="+type+"&city="+city+"&price="+price+"&area="+area+"&lat="+lat+"&lng="+lng+"&details="+details;
    
    //Ajax Request for Bubble
    new Ajax.Request(url ,
    {
        method:'get',
        onLoading: function(){
            $('status').appear();
            $('status').innerHTML="<div style=\"width:100%;\">Kaydediliyor...</div>";
        },
        onSuccess: function(transport){
            var response = transport.responseText || "no response text";
            $('status').innerHTML=response;
            $('status').fade({ duration: 3.0 });
        },
        onFailure: function(){
            alert('Something went wrong...');
        }
    });
}

function search(){
    var offerType=document.getElementById('offerType').value;
    var type=document.getElementById('propertyType').value;
    var city=document.getElementById('city').value;
    var fromPrice=document.getElementById('fromPrice').value;
    var toPrice=document.getElementById('toPrice').value;
    var url="";
    
    if(type == 1){
        url+="parts/index/resultApartment.php?";
    }
    
    var variables="offerType="+offerType+"&propertyType="+type+"&city="+city+"&fromPrice="+fromPrice+"&toPrice="+toPrice;
    MakeRequest(url+variables,'result');
    loadData("data.php?"+variables);
    
}

function ifocus(elem){
    $(elem).addClassName('blueBorder');
}

function iblur(elem){
    $(elem).removeClassName('blueBorder');
}

function showLoadingImage(){
    return "<div style=\"width:100%; text-align: center;\"><img src=\"img/loading.gif\"></div>";
}